import requests  

class PrometheusMetricClass:
    def __init__(self, prometheus_metric_url, username=None, password=None) -> None:
        self.prometheus_metric_url = prometheus_metric_url
        self.username = username
        self.password = password

    def metric_query(self, params):

        response = requests.get(self.prometheus_metric_url, params=params)  
        
        # 检查请求是否成功  
        if response.status_code == 200 or response.status_code == 201:  
            print('请求成功')  
            # return response.json()["data"]["result"][0]["values"]
            data = response.json()
            return data["data"]["result"]
        else:  
            print(f'请求失败: {response.status_code} - {response.text}')
        
        return False
